import json
import torch
from typing import Optional
def Savetar(data: dict = None,
            path_file: str = None,
            type: str = 'read'
            ):

    assert type in ['write','read']
    if type == 'write':
        with open(path_file, 'r+') as file:
            content = file.read()
            content = json.loads(content)

        for key in data.keys():
            content[key] = data[key]

        content = json.dumps(content)
        with open(path_file, 'w+') as file:
            file.write(content)

    elif type == 'read':
        with open(path_file, 'r+') as file:
            content = file.read()
            content = json.loads(content)
        return content



